package edu.odu.cs.sstore.gateway;

import org.aspectj.lang.JoinPoint;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.security.core.context.SecurityContextHolder;



public class AuditLoggingAdvice  {

	public void auditMethodInvocation(JoinPoint joinPoint) {
		
		if(joinPoint instanceof MethodInvocationProceedingJoinPoint) {
			
			MethodInvocationProceedingJoinPoint obj = (MethodInvocationProceedingJoinPoint)joinPoint;
			
			String target = obj.getSignature().toShortString();
			String user = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
		
			System.out.println("User ["+user+"] called method ["+target+"]");
			
		}
		
	}
	
}
